package com.amumu.netctoss.action;

import java.util.List;

import javax.annotation.Resource;

import com.amumu.netctoss.dao.RoleDao;
import com.amumu.netctoss.entity.Privilege;
import com.amumu.netctoss.entity.Role;
import com.amumu.netctoss.util.PrivilegeReader;

public class RoleAction extends BaseAction {
	@Resource
	private RoleDao dao;

	private List<Role> roleList;
	private Role role;
	private List<Privilege> privileges;

	//添加
	public String save() {
		try {
			dao.save(role);
			ok = true;
		} catch (Exception e) {
			ok = false;
			e.printStackTrace();
		}
		return SUCCESS;
	}

    //转到添加页面
	public String toAdd() {
		privileges = PrivilegeReader.getPrivileges();
		return SUCCESS;
	}

	//列表显示
	public String list() {

		try {
			setPageCount(dao.getPageCount(PAGE_SIZE));
			roleList = dao.getList(page, PAGE_SIZE);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	//转到修改页面
	public String toUpdate() {
		privileges = PrivilegeReader.getPrivileges();
		try {
			role = dao.findById(id);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	//执行修改
	public String update() {
		try {
			dao.update(role);
			ok = true;
		} catch (Exception e) {
			ok = false;
			e.printStackTrace();
		}
		return SUCCESS;
	}

	//执行删除
	public String delete() {
		try {
			dao.delete(id);
			ok = true;
		} catch (Exception e) {
			ok = false;
			e.printStackTrace();
		}
		return SUCCESS;
	}


	
	
	
	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}

	public List<Role> getRoleList() {
		return roleList;
	}

	public List<Privilege> getPrivileges() {
		return privileges;
	}

	// getter and setter

}
